﻿using LowCoding.Application.Sys;
using LowCoding.Application.Sys.Role;
using LowCoding.Common;
using LowCoding.Dto;
using LowCoding.Dto.Sys;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace LowCoding.API.Controllers.sys.Role
{
    /// <summary>
    /// 角色API
    /// </summary>
    /// [Authorize]
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SysRoleController : BaseController
    {
        private readonly ISysRoleService _sysroleservice;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="sysroleservice"></param>
        /// <param name="syscompanyservice"></param>
        public SysRoleController(ISysRoleService sysroleservice)
        {
            _sysroleservice = sysroleservice;
        }

        /// <summary>
        /// 分页查询角色列表（接口可用）
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("Display")]
        [AllowAnonymous]
        public async Task<ResponseMessageModel> SysRolePage([FromQuery] SysRoleSearchInput input)
        {
            return Success(await _sysroleservice.GetPageListAsync(input));
        }
        /// <summary>
        /// 查询所有角色列表（接口可用）
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("DisplayAll")]
        [AllowAnonymous]
        public async Task<ResponseMessageModel> SysRolePageTwo()
        {
            return Success(await _sysroleservice.SysRolePageTwo());
        }
        /// <summary>
        /// 角色下拉框（接口可用）
        /// </summary>
        /// <returns></returns>
        [HttpGet("DisplayOptions")]
        [AllowAnonymous]
        public async Task<ResponseMessageModel> GetRoleOptionsAsync()
        {
            return Success(await _sysroleservice.GetRoleOptionsAsync());
        }
        /// <summary>
        /// 查询单条角色（接口可用）
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet("DisplayKey")]
        [AllowAnonymous]
        public async Task<ResponseMessageModel> SysRoleQuery([FromQuery] string key)
        {
            return Success(await _sysroleservice.GetSingleAsync(key));
        }
        /// <summary>
        /// 添加角色（接口可用）
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("Insert")]
        [AllowAnonymous]
        public async Task<ResponseMessageModel> InsertRoleAsync(SysRoleInput input)
        {
            return Success(await _sysroleservice.InsertRoleAsync(input));
        }
        /// <summary>
        /// 更新角色（接口可用）
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut("Update")]
        [AllowAnonymous]
        public async Task<ResponseMessageModel> RoleUpdateAsync([FromForm] SysRoleInput input)
        {
            return Success(await _sysroleservice.RoleUpdateAsync(input));
        }

        /// <summary>
        /// 删除角色（接口可用）
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpDelete("DeleteKey")]
        [AllowAnonymous]
        public async Task<ResponseMessageModel> DelRoleAsync(List<string> id)
        {
            return Success(await _sysroleservice.DelRolesAsync(id));
        }

        /// <summary>
        /// 批量删除角色（接口可用）
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        [HttpDelete("DeleteKeys")]
        [AllowAnonymous]
        public async Task<ResponseMessageModel> DelRolesAsync([FromForm] List<string> keys)
        {
            return Success(await _sysroleservice.DelRolesAsync(keys));
        }
    }
}
